package com.ltu.controller.customize;

import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ltu.model.request.base.BaseFilterPageReq;
import com.ltu.model.request.base.BaseIdReq;
import com.ltu.model.response.base.CodeDataResp;
import com.ltu.service.impl.BaseServiceImpl;


import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.ltu.ai.sparkdesk.websocket.AiContextManager;
import com.ltu.domain.mp_entity.customize.PushAdEntity;
import com.ltu.mapper.customize.PushAdMapper;


/**
 * <p>
 * 设备的广告列表 前端控制器
 * </p>
 *
 * @author 若尘
 * @since 2024-10-25
 */
@RestController

@RequestMapping("/PushAd")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags= "设备的广告列表")
public class PushAdController extends BaseServiceImpl<PushAdMapper, PushAdEntity>{
	private final AiContextManager aiContextManager;
	
    @ApiOperation(value="获取分页列表")
    @RequestMapping(value="/getMePage", method= RequestMethod.POST)
    public CodeDataResp<Page<PushAdEntity>> getMePage(@RequestBody  BaseFilterPageReq<PushAdEntity> req ) {
    	return super.getMePage(req);
    }
    
    @ApiOperation(value="获取列表")
    @RequestMapping(value="/getList", method= RequestMethod.POST)
    public CodeDataResp<List<PushAdEntity>> getList(@RequestBody  BaseFilterPageReq<PushAdEntity> req ) {
        return super.getMeList(req);
    }
    
    @ApiOperation(value="获取列表")
    @RequestMapping(value="/getListByDeviceMac", method= RequestMethod.POST)
    public CodeDataResp<List<PushAdEntity>> getListByDeviceMac(@RequestBody  BaseFilterPageReq<PushAdEntity> req ) {
    	return super.getMeList(req);
    }

    @ApiOperation(value="新增/保存")
    @RequestMapping(value="/edit", method= RequestMethod.POST)
    public CodeDataResp edit(@RequestBody PushAdEntity req) {
        return super.edit(req);
    }
    
//    @ApiOperation(value="批量修改数据")
//    @RequestMapping(value="/edits", method= RequestMethod.POST)
    public CodeDataResp edits(@RequestBody List<PushAdEntity> reqs) {
    	super.saveOrUpdateBatch(reqs);
    	return   CodeDataResp.valueOfSuccessEmptyData();
    }
    
    
    	@ApiOperation(value="获取详情")
    @RequestMapping(value="/getDetail/{id}", method= RequestMethod.GET)
    public CodeDataResp<PushAdEntity> getDetail(@PathVariable String id) {
 		BaseIdReq req=new BaseIdReq(id);
        return super.getDetail(req);
    }
    

 	 @ApiOperation(value="删除")
     @RequestMapping(value="/remove/{id}", method= RequestMethod.GET)
     public CodeDataResp remove(@PathVariable String id) {
     	BaseIdReq req=new BaseIdReq(id);
     	PushAdEntity  target =  this.getById(id);
    	//通过websocket给指定设备传输广告的视频文件地址 视频文件的访问关闭访问鉴权
    	aiContextManager.pushAd(Arrays.asList(target.getDeviceMac()));
     	return super.remove(req);
     }
     
 //   @ApiOperation(value="删除s")
//    @RequestMapping(value="/removes", method= RequestMethod.POST)
    public CodeDataResp removes(@RequestBody List<Integer> ids) {
    		super.removeByIds(ids);
        return CodeDataResp.valueOfSuccessEmptyData();
    }

}

